package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.ListDealHandler;
import com.cungmua.app.model.request.ListDealRequest;
import com.cungmua.app.model.response.ListDealResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/17/14.
 */
public class HotDealTask extends AuthenticatedTask<ListDealRequest, Void, ListDealResponse> {
    private final Context context;
    private final ListDealHandler handler;

    public HotDealTask(Context context, ListDealHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected ListDealResponse doInBackground() throws RetrofitError {
        ListDealRequest request = params[0];

        return service.getListHotDeal(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(ListDealResponse listDealResponse) {
        handler.onListDealReceived(listDealResponse);
    }
}
